package com.topcheer.provider.common.config;

import com.topcheer.provider.rbac.entity.Operation;
import com.topcheer.provider.rbac.service.OperationService;
import com.topcheer.common.base.util.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationStartedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author xutao
 * @Package com.example.baseline.common.config
 * @Description: ${todo}
 * @date 2020/4/2 11:25
 */
//@Component
public class AfterStartListener implements ApplicationListener<ApplicationStartedEvent> {

    @Autowired
    OperationService operationService;
    @Override
    public void onApplicationEvent(ApplicationStartedEvent applicationStartedEvent) {
        List<String> allMvcPattern = WebUtil.getAllMvcPattern();
        /*List<Operation> collect = allMvcPattern.stream().map(pattern -> {
            Operation operation = new Operation();
            operation.setOperationUrl(pattern);
            return operation;
        }).collect(Collectors.toList());*/
        allMvcPattern.forEach(pattern ->{
            Operation operation = new Operation();
            operation.setOperationUrl(pattern);
            operationService.insertOrNo(operation);
        });
    }
}
